//
//  TaskListCell.m
//  Trackit
//
//  Created by yaodaobin on 2017/4/9.
//  Copyright © 2017年 yaodaobin. All rights reserved.
//

#import "TaskListCell.h"

@implementation TaskListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self initUI];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

- (void)initUI {
    kWeakSelf
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:self.titleLabel];
    
    self.dateLable = [[UILabel alloc] init];
    self.dateLable.textColor = [UIColor lightGrayColor];
    self.dateLable.font = [UIFont systemFontOfSize:14];
    self.dateLable.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.dateLable];

    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.textColor = [UIColor lightGrayColor];
    self.contentLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.contentLabel];

    self.statusLabel = [[UILabel alloc] init];
    self.statusLabel.textColor = [UIColor greenColor];
    self.statusLabel.font = [UIFont systemFontOfSize:14];
    self.statusLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.statusLabel];

    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.leading.offset(20);
        make.trailing.lessThanOrEqualTo(weakSelf.dateLable.mas_leading).offset(-10);
    }];
    [self.dateLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLabel.mas_top);
        make.trailing.offset(-20);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(5);
        make.leading.equalTo(weakSelf.titleLabel.mas_leading);
        make.trailing.lessThanOrEqualTo(weakSelf.statusLabel.mas_leading).offset(-10);
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_greaterThanOrEqualTo(weakSelf.dateLable.mas_bottom).offset(5);
        make.trailing.equalTo(weakSelf.dateLable.mas_trailing);
        make.bottom.equalTo(weakSelf.contentLabel.mas_bottom);
        make.bottom.equalTo(weakSelf.contentView.mas_bottom).offset(-5).with.priorityHigh();
    }];
    
    //设置label1的content compression 为1000
    [self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
                                                         forAxis:UILayoutConstraintAxisHorizontal];
    //设置右边的label2的content compression 为250
    [self.dateLable setContentCompressionResistancePriority:UILayoutPriorityRequired
                                                             forAxis:UILayoutConstraintAxisHorizontal];
    //设置label1的content compression 为1000
    [self.contentLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
                                                     forAxis:UILayoutConstraintAxisHorizontal];
    //设置右边的label2的content compression 为250
    [self.statusLabel setContentCompressionResistancePriority:UILayoutPriorityRequired
                                                    forAxis:UILayoutConstraintAxisHorizontal];

}

- (void)setTaskListModel:(TaskListModel *)model {
    self.titleLabel.text = model.taskName;
    self.dateLable.text = model.createCalendarDate;
    self.contentLabel.text = model.collectDataTypeName;
//    self.statusLabel.text = model.taskStatusName;
    if (model.finished) {
        self.statusLabel.textColor = [UIColor colorWithHex:0xABABAB alpha:1.0f];
        self.statusLabel.text = @"已完成";
    } else {
        if ([model localPathExisted]) {
            self.statusLabel.textColor = [UIColor redColor];
            self.statusLabel.text = @"未提交";
        } else {
            self.statusLabel.textColor = [UIColor colorWithHex:0x228B22 alpha:1.0f];
            self.statusLabel.text = @"未开始";
        }
    }
}

@end
